{% extends 'common/base.html' %}
{% import 'common/page.html' as pg %}
{% block css %}
{% endblock %}
{% block content %}
    <section class="content-header">
        <div>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 题库管理</a></li>
                <li class="active">试题列表</li>
            </ol>
        </div>
    </section>
    <section class="content" id="showcontent">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header">
                        <h3 class="box-title">试题列表</h3>
                        <div class="box-tools">
                            <div class="float-right" style="margin-right:5px;width: 200px">
                                <form action="" method="GET">
                                    <div class="input-group input-group-sm">
                                        <input type="text" class="form-control" name="keyword"
                                               placeholder="请输入题目信息或类别" value="{{ keyword }}">
                                        <span class="input-group-btn">
                                             <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
                                        </span>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-striped toggle-arrow-tiny">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>题目</th>
                                <th>类型</th>
                                <th>是否可用</th>
                                </th>
                                <th>操作事项</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for v in page_data.items %}
                                <tr data-toggle="collapse" data-target="#op{{ v.id }}" aria-expanded="false"
                                    aria-controls="collapseExample">
                                    <td>{{ v.id }}</td>
                                    <td style="max-width: 400px;text-align: left">{{ v.context }}</td>
                                    <td>{{ v.question_type.name }}</td>
                                    {% if v.state == 1 %}
                                        <td>是</td>
                                    {% else %}
                                        <td>否</td>
                                    {% endif %}
                                    <td>
                                        {% if  v.user_id == session['user_id'] %}
                                            <a href="{{ url_for('main.question_edit', id=v.id ) }}"
                                               class="label label-success">编辑</a>&nbsp;
                                            <a href="{{ url_for('main.question_del', id=v.id ) }}"
                                               class="label label-danger" onclick="del({{ v.context }})">删除</a>
                                        {% endif %}
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="5" style="margin: 0;padding: 0">
                                        <div class="collapse"
                                             style="width: 100%;text-align: left;margin: 5px 50px;max-width: 1000px;"
                                             id="op{{ v.id }}">
                                            <div>
                                                <strong>{{ v.question_type.name }}</strong>
                                            </div>
                                            <div style="margin:5px 20px ">
                                                <strong>{{ v.context }}</strong>
                                            </div>
                                            {% if v.question_type.id == 1 or v.question_type.id == 2 %}
                                                <div>
                                                    <div style="float:left;">
                                                        <p style="float:left; margin: 5px 20px">A.{{ v.op_a }}</p>
                                                        <p style="float:left; margin: 5px 20px">B.{{ v.op_b }}</p>

                                                    </div>
                                                    <div style="float:left;">
                                                        <p style="float:left; margin: 5px 20px">C.{{ v.op_c }}</p>
                                                        <p style="float:left; margin: 5px 20px">D.{{ v.op_d }}</p>
                                                    </div>
                                                </div>
                                            {% endif %}

                                            {% if v.question_type.id == 3 %}
                                                <div style="clear: left;color:#008000"> 答案:
                                                    {% if v.answer == "1" %}
                                                        <span style="color: green">对</span>
                                                    {% else %}
                                                        <span style="color: red">错</span>
                                                    {% endif %}
                                                </div>
                                            {% else %}
                                                <div style="clear: left;color:#008000"> 答案： {{ v.answer }}</div>
                                            {% endif %}
                                            <div>
                                                <p style="float: left; margin-right: 50px"><strong>是否启用:</strong>
                                                    {% if v.state == 1 %}
                                                        <span style="color: green">是</span>
                                                    {% else %}
                                                        <span style="color: red">否</span>
                                                    {% endif %}
                                                </p>
                                                <p style="float: left; margin-right: 50px"><strong>是否公开:</strong>
                                                    {% if v.is_public == 1 %}
                                                        <span style="color: green">是</span>
                                                    {% else %}
                                                        <span style="color: red">否</span>
                                                    {% endif %}
                                                </p>
                                                <p><strong>所属用户:</strong>
                                                    <span style="color: #0e9aef">{{ v.user.username }}</span>
                                                </p>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        {{ pg.page(page_data,'main.question_list',keyword) }}
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!--内容-->
{% endblock %}
{% block js %}
    <script>
        $(function () {
            var msg_ok = {{get_flashed_messages(category_filter=["ok"])|tojson}};
            if (msg_ok.length > 0 && msg_ok != "") {
                layer.open({
                    title: '成功',
                    content: msg_ok.toString(),
                    icon: 1,
                    times: 2000
                });
            }
            var msg_err = {{get_flashed_messages(category_filter=["err"])|tojson}};
            if (msg_err.length > 0 && msg_err != "") {
                layer.open({
                    title: '失败',
                    content: msg_err.toString(),
                    icon: 2,
                    times: 2000
                });
            }
        })

        function del(name) {
            return confirm("确定删除[" + name + "]?");
        }
    </script>
{% endblock %}